

var user_id = localStorage.getItem("user_id");//user_id   
var is_this;

mui.init({
	swipeBack: false,
	//下拉刷新
	pullRefresh: {
		container: "#refreshContainer", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
		up: {
			height: 50, // 可选.默认50.触发上拉加载拖动距离
			auto: true, // 可选,默认false.自动上拉加载一次
			contentrefresh: "正在加载...", // 可选，正在加载状态时，上拉加载控件上显示的标题内容
			contentnomore: '没有更多的数据了', // 可选，请求完毕若没有更多数据时显示的提醒内容；
			callback: pullupRefresh //加载数据方法 
		}
	}
});

/*var pagesize = 5; //每页条数
var number = 0; //页数
var isOver = false; //是否加载完  */
function buddy_dynamics_fun() { //首页关注列表
	var number = $("#number").val();
	user_id = user_id ? user_id : '';
	interfRequest.buddy_dynamics.data = { 
		number: number,
		pagesize: 5,
		lat: "",
		lon: "",
		user_id: user_id
	}
	socialRequest(interfRequest.buddy_dynamics); //异常处理
}

//下拉加载
function pullupRefresh() {
	setTimeout(function() {
		mui('#refreshContainer').pullRefresh().disablePullupToRefresh();
		setTimeout(function() {
			var isOver = $("#isOver").val(); 
			mui('#refreshContainer').pullRefresh().endPullupToRefresh((isOver)); //参数为true代表没有更多数据了。  
			buddy_dynamics_fun(); //ajax   
		}, 500);
	}, 500);
}
 
//图片大小处理
var width=$(".list_img .mui-col-xs-4").width();
$(".list_img .mui-col-xs-4").height(width); 
 
mui.previewImage(); //图片预览

//登录
mui('body').on('tap', '#login', function() {
	/*mui.openWindow({
		url: '../user/login.html',
		id: 'login',
	});*/
	window.top.location.href = '../user/login.html';
})
 
//推荐
mui('body').on('tap', '.tad_title', function() {
	window.top.location.href = this.href; 
});
//用户
mui('body').on('tap', '.recommend_top img', function() {
	var id = $(this).siblings().find(".nickname").attr("id");
	//var mag = $("#mag").val();//提示  
	if(mag == "请先登录"){//判断是否登录 
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: 'html/user/login.html',
					id: 'login',
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		}) 
	}else{
		mui.openWindow({
			url: '../video/fan_pages.html', 
			extras: {
				publisher: id,
			},
			createNew: true
		});
	}
})

//点赞动态
mui('body').on('tap', '.zan', function() {
	//var mag = $("#mag").val();//提示   
	is_this = $(this);
	var dynamic_id = $(this).parents(".recommend_list").attr("id");
	interfRequest.dynamic_label.data = {
		user_id: user_id,
		dynamic_id: dynamic_id, //true	普通参数	int		动态id
	}
	socialRequest(interfRequest.dynamic_label); //异常处理 
	
	
});

/*点赞*/
function dynamic_labelHandle(data) {
	//console.log(JSON.stringify(data));
	if(data.error_code == 10000) {  
		is_this.find(".iconfont").addClass("lover");
		var dz_num = is_this.find(".iconfont").siblings().text(); 
		is_this.find(".iconfont").siblings().text(parseInt(dz_num) + 1);
	} else { 
		$("#zan").val(data.error_code);
		//mui.toast("该条动态已赞");    
	}
}

//查看详情
mui('body').on('tap', '.content_text', function() {
	var id =  $(this).parents(".recommend_list").attr("id");
	mui.openWindow({
		url: 'graphic_details_page.html',
		id: 'graphic_details_page',
		extras: {
			dynamic_id: id,
		},
		createNew: true
	});
});


//评论 
mui('body').on('tap', '.comment', function() {
	var id =  $(this).parents(".recommend_list").attr("id");
	mui.openWindow({
		url: 'graphic_details_page.html',
		id: 'graphic_details_page',
		extras: {
			dynamic_id: id,
		},
		createNew: true
	});
}); 

//更多
mui('body').on('tap', '.more', function() {
	is_this =  $(this);//
	//$("#report").attr("sta",id);
}); 

//举报
mui('body').on('tap', '#report', function() {
	var mag = $("#mag").val();//提示  
	var dynamicid = is_this.parents(".recommend_list").attr("id");//动态id
	var passiveid = is_this.parent().siblings(".recommend_top").find(".nickname").attr("id");//动态用户id
	var username = is_this.parent().siblings(".recommend_top").find(".nickname").text();//动态用户昵称 
	if(mag == "请先登录"){//判断是否登录  
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: 'html/user/login.html',
					id: 'login', 
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		}) 
	}else{
		mui.openWindow({
			url: 'Report.html',
			id: 'Report', 
			extras: {
				dynamic_id: dynamicid,
				passive_id: passiveid,
				passive_username: username
			},
			createNew: true
		});
	}  
});  


//底部菜单
mui('body').on('tap', '.mui-tab-item', function() {
	window.top.location.href = this.href;
	$(this).addClass("mui-active");
});
mui.init({
	swipeBack: false
});
window.addEventListener('refresh_method', function(e) { //执行刷新
	location.reload();
}); 

//消息
mui('body').on('tap', '#my_news', function() {
	var mag = $("#mag").val();//提示  
	if(mag == "请先登录"){//判断是否登录 
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: '../user/login.html',
					id: 'login',
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		}) 
	}else{
		window.top.location.href = "../news/fx_message.html";
	}  
	
});

//我的
mui('body').on('tap', '#user', function() {
	var mag = $("#mag").val();//提示  
	if(mag == "请先登录"){//判断是否登录 
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: '../user/login.html',
					id: 'login',
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		}) 
	}else{
		window.top.location.href = "../my/my.html";
	}  
	
});

//发布动态
mui('body').on('tap', '.public_menu_img a', function() {
	var sta = $(this).attr("sta");
	var mag = $("#mag").val();//提示  
	if(mag == "请先登录"){//判断是否登录 
		var btnArray = ['否', '是'];
		mui.confirm(mag, '提示', btnArray, function(e) {
			if(e.index == 1) {
				/*mui.openWindow({
					url: 'html/user/login.html',
					id: 'login',
				});*/
				window.top.location.href = '../user/login.html';
			} else {}
		}) 
	}else if(sta == 1) { //发布图文
		mui.openWindow({
			url: 'issued_by.html',
			id: 'issued_by',
		});
	} else if(sta == 2) { //发布视频
		mui.openWindow({
			url: 'issued_video.html',
			id: 'issued_video',
		});
	}
	 
});

//用户信息
function user_info() {
	interfRequest.user_info.data = {
		refresh: 1 //true	普通参数	string		刷新状态1代表刷新
	}
	socialRequest(interfRequest.user_info); //异常处理 
}


//搜索
mui('body').on('tap', '#recommend_search', function() {
	window.top.location.href = "landing_page0.html"
});


//视频播放
mui('body').on('tap', '.img_video', function() {
	var videoMedia = $(this).siblings().children("source").attr("src");
	var bu = document.getElementById("videoMedia"); 
	bu.src = videoMedia;
	bu.play();  
	$(".video_ji").show();   
});

//关闭视频
mui('body').on('tap', '.back', function() {
	$(".video_ji").hide();
	var bu = document.getElementById("videoMedia");
	bu.innerHTML = '';
	bu.pause();
});



//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		user_info();
	})
}


/*(function($) {
	$('.mui-scroll-wrapper').scroll({
		indicators: true //是否显示滚动条
	});
})(mui);*/